var _ = require('lodash');
var path = require('path');
var webpack = require('webpack');
var Clean = require('clean-webpack-plugin');
var baseConfig = require('./base.config')
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var CopyWebpackPlugin = require('copy-webpack-plugin');

var config = _.merge(baseConfig, {
  output: {
    path: path.resolve(__dirname, '../dist/build'),
    publicPath: 'build/',
    filename: '[name].[hash:8].js',
    chunkFilename: 'chunk.[id].[hash:8].js',
    pathinfo: true
  },
  plugins: [
    new Clean(['dist/build'], {
      root: path.resolve(__dirname, '../'),
      verbose: true,
      dry: false
    }),
    new CopyWebpackPlugin([
      {from: './app/web/assets', to: '../assets'},
    ]),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      },
      minimize: true,
      exclude: [
        /node_modules/,
        /bower_components/
      ],
      output: {
        comments: false,
        ascii_only: true
      }
    }),
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': JSON.stringify('production')
      }
    }),
    new HtmlWebpackPlugin({
        filename: '../index.html',
        template: './app/web/temp/index.html',
    }),
    new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.[hash:8].js", Infinity),
    new ExtractTextPlugin('[name].[hash:8].css')
  ].concat(baseConfig.plugins),
});

module.exports = config;
